Issue saving a linked target module

I make a change to either object heading or object text in a source module and then want to run a script to make all linked target module's object heading and object text match. I have no problem making the changes but I cannot get the save and close function to work properly. I have tried multiple variations, the closest to getting it working is marked by "*" off to the left near the bottom of the code below. However the result is the target module will close but when I open the target module manually (just to check) the object heading and object text that has changed appears red in addition to asking me if I want to save changes when I try to close the target module, signaling the script failed to save before it closed the target module. Any advice on what is going wrong?

{Code Snippet}
Module SourceMod = current
Object SourceObj
Link lnk
ModName_ TargetModName
int ObjAbsNumber
int saveTargetModArg
int openTargetModArg = 0
int autoSaveTargetModArg = 1
//loop through each object in the Source Module
for SourceObj in SourceMod do {

ObjAbsNumber = SourceObj."Absolute Number"

//stream the absolute number of the source module object to the .txt log file
out << (NLS_("Object Absolute Number in Source Module: " ObjAbsNumber "\n"))

//get the string of the object in the Source Module
string SourceObjHeadingString = SourceObj."Object Heading"
string SourceObjTextString = SourceObj."Object Text"
//--------------------------------------------------------------------------------------------------------
//-------------------------------------Loop 2 (nested)----------------------------------------------------

//loop through each out link in the Source Module object in this step of above loop. "*" means any link module
for lnk in (Object SourceObj) -> "*" do {

//get the name of the Target Module in order to open it in exclusive edit mode
TargetModName = target(lnk)
string TargetModNamePath = fullName(TargetModName)
//--------------------------------------------------------------------------------------------------------
//-------------------------------------open/edit Target Module--------------------------------------------

//the boolean argument is to specify visibility of the opened module, desired by user
if (openTargetModArg == 1) {
Module TargetMod = edit(TargetModNamePath,true)
}
else if (openTargetModArg == 0) {
Module TargetMod = edit(TargetModNamePath,false)
}

print "\t Path of Target Module: " TargetModNamePath "\n"
//get a handle on the object in the Target Module for the current link in the current object
Object TargetObj = target(lnk)

//get the string of the object in the Target Module
string TargetObjHeadingString = TargetObj."Object Heading"
string TargetObjTextString = TargetObj."Object Text"
//--------------------------------------------------------------------------------------------------------
//---------------compare the object strings from the Source Module to the Target Module-------------------

//first check if the object attr. in the Target Module is an Object Heading or Object Text attr.

//-------------------case 1-------------------
//in this case the object attr. is an Object Heading
if (TargetObjHeadingString != "" && TargetObjTextString == "") {
//stream the target object heading to the .txt file
print"\t Target Module Object Heading was found: " TargetObjHeadingString "\n"
//second check if the Target Module is equivalent to the Source Module

//-------------------case 1 A-------------------
//in this case the Target Module is the same as the Source Module
if (TargetObjHeadingString == SourceObjHeadingString) {
//no change, they are the same
//stream the change status of the object heading to the .txt file
print "\t\t Target Module Object Heading is the same as the Source Module Object Heading: \n"
}

//-------------------case 1 B-------------------
//in this case the Target Module differs from the Source Module
else if (TargetObjHeadingString != SourceObjHeadingString) {
//change the Target Module to the contents of the Source Module
TargetObj."Object Heading" = SourceObjHeadingString
//stream the change status of the object heading to the .txt file
//show the Target Module object heading string
print "\t\t ******Target Module Object Heading differs from the Source Module Object Heading****** \n"
print "\t\t ******Proposed Object Heading change: " SourceObjHeadingString "\n"
}
}
//-------------------case 2-------------------
//in this case the object attr. in the Target Module is an Object Text
else if (TargetObjHeadingString == "" && TargetObjTextString != "") {
//stream the target text to the .txt file
print "\t Target Module Object Text was found: " TargetObjTextString "\n"

//second check if the Target Module is equivalent to the Source Module

//-------------------case 2 A-------------------
//in this case the Target Module is the same as the Source Module
if (TargetObjTextString == SourceObjTextString) {
//no change, they are the same
//stream the change status of the target text to the .txt file
print "\t\t Target Module Object Text is the same as the Source Module Object Text \n"
}

//-------------------case 2 B-------------------
//in this case the Target Module differs from the Source Module
else if (TargetObjTextString != SourceObjTextString) {
//change the Target Module to the contents of the Source Module
TargetObj."Object Text" = SourceObjTextString
//stream the change status of the target text to the .txt file
print "\t\t ******Target Module Object Text differs from the Source Module Object Text****** \n"
print "\t\t ******Proposed Object Text change: " SourceObjTextString "\n"
}
}
//-------------------case 3-------------------
else {
//stream a Warning message the objects did not properly align for comparison
print "******WARNING! THE OBJECTS DID NOT MATCH PROPERLY FOR COMPARISON!****** \n"
}

//argument specified by user in first GUI, in this case YES autosave all Target Modules to improve efficiency

  • if (autoSaveTargetModArg == 1) {*
  • *
  • //argument for saving as script progresses through loop*
  • saveTargetModArg = 0*
  • void save(Module TargetModName)*
  • //second argument (true) is to save the module before closing*
  • bool myOpt = true*
  • close(TargetModNamem, myOpt)*
  • } //end if*
} //end for lnk in o loop
//--------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
} //end for o in m loop

{End Code Snippet}
SystemAdmin - Wed Mar 13 09:23:43 EDT 2013

Re: Issue saving a linked target module
SystemAdmin - Wed Mar 13 09:25:04 EDT 2013

Sorry, to clarify this is the section of the {Code Snippet} I am concerned about:

//argument specified by user in first GUI, in this case YES autosave all Target Modules to improve efficiency

•if (autoSaveTargetModArg == 1) {*
•*
•//argument for saving as script progresses through loop*
•saveTargetModArg = 0*
•void save(Module TargetModName)*
•//second argument (true) is to save the module before closing*
•bool myOpt = true*
•close(TargetModNamem, myOpt)*
•} //end if*

Re: Issue saving a linked target module
llandale - Wed Mar 13 13:08:04 EDT 2013

Just:
  • save(mod)
  • close(mod)

That optional 2nd parameter to "close(mod, opt)"
  • is not: "If needs saving, save before closing"
  • it is : "If needs saving, ask the user to save before closing".

-Louie